﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;

namespace Automobile.service.UI
{
    public partial class Stock_list : System.Web.UI.Page
    {
        StockBLL bll = new StockBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            { 
                StockDatabingding();
            }
        }
        protected void StockDatabingding()
        {
            Label1.Text = bll.GetStockCount().ToString();
            Repeater1.DataSource = bll.ShowListDataTable();
            Repeater1.DataBind();
        }
        protected void Repeater1_ItemCommand(object sender,RepeaterCommandEventArgs e)
        {
            string ename = e.CommandName;//获取当前要执行的命令
            string id = e.CommandArgument.ToString();
            switch (ename)
            {
                case "del":
                    if (bll.DelStock(id) > 0)
                    {
                        JournalBLL jbll = new JournalBLL();
                        jbll.AddJourna_DelStock(Convert.ToInt32(Session["empid"]),id);
                        Response.Write("<script>alert('删除成功');</script>");
                        StockDatabingding();
                    }
                    else
                    {
                        Response.Write("<script>alert('服务器忙');</script>");
                    }
                    break;
                //case "upd":
                //    Response.Redirect("Stock_Edit.aspx?id=" + id);
                //    break;
            }
        }
        protected void Unnamed_ServerClick(object soure,EventArgs e)
        {
            string Product_Name = Request.Form["Product_Name"].ToString();
            Repeater1.DataSource = bll.GetStockByName(Product_Name);
            Repeater1.DataBind();
        }
    }
}